package com.sharkburner.aeris.ui.module.article.composition;

import com.sharkburner.aeris.dao.entity.Article;
import com.sharkburner.common.listener.GridViewListener;
import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Table;

/**
 * 
 * @author piu
 * 
 */
public class ArticleCellRender implements Table.ColumnGenerator {

    /**
	 * 
	 */
    private static final long serialVersionUID = -1179064572432275924L;
    private GridViewListener<Article> gridViewListener;

    public ArticleCellRender(GridViewListener<Article> gridViewListener) {
	super();
	this.gridViewListener = gridViewListener;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Object generateCell(Table source, Object itemId, Object columnId) {

	BeanItem<Article> item = (BeanItem<Article>) source.getItem(itemId);
	Object object = item.getBean();

	if (object instanceof Article) {
	    /*
	     * Property itemProperty = item.getItemProperty(
	     * ArticleModel.DESCR);
	     */
	    Article article = (Article) object;

	    return gridViewListener.renderObject(article);
	}

	return String.valueOf(object);
    }

    public void changeView(GridViewListener<Article> view) {
	gridViewListener = view;
    }

}
